<%--
  Author: Al-assad 余林颖
  E-mail: yulinying_1994@outlook.com
  Date: 2018/1/10 11:52 
  Description:
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>WebSocket 测试</title>
    <script type="text/javascript">
        var url = 'ws://' + window.location.host + '<%= request.getContextPath() %>/pm25'; //本机测试，真实常见下更换为服务主机 url

        var sock = new WebSocket(url);
        sock.onopen = function(){
            changeCity("bj");
        };
        sock.onmessage = function(e){
            console.log("get:"+ e.data);
            document.getElementById("showData").innerHTML = e.data;
        };

        function changeCity(city){
            console.log("send: "+city);
            sock.send(city);
        }
    </script>
</head>
<body>
    <h1>PM 2.5 AQI 实时刷新数据</h1>
    <button onclick="changeCity('bj')">北京</button>
    <button onclick="changeCity('gz')">广州</button>
    <br/>
    <p id="showData"></p>
</body>
</html>
